# _*_ coding: utf-8 _*_
import pytest
import unittest
from time import sleep

from selenium import webdriver
from Data.md5_demo import Md
from Data.mdb_connect_demo import AccessDate
from Data.read_yaml import get_success
from Operate import fileOperate
from Operate.BusinessOperate import BusinessOperate
from Page.CommonPage import CommonPage
from Operate.BaseOperate import BaseOperate
from ddt import data, unpack, ddt
from Data.read_yaml import get_fail, get_success
from parameterized import parameterized, parameterized_class


# 主测试类继承自测试框架unittest
class MainCase(unittest.TestCase):
    p = None

    def setUp(self):
        # 使用谷歌浏览器，关闭多任务分发
        # self.driver = BaseOperate(browser="chrome", isMultitask=False)
        self.driver = BaseOperate(browser="chrome")

        # 测试之前,启动浏览器,打开一个设定好的网址
        self.driver.get("https://market-cloud.ideamake.cn/admin/index.html#/login")
        # 最大化窗口
        self.driver.max_window()

        # 实例化页面 将页面放于此
        # 基础信息页
        self.base_info_page = CommonPage(self.driver).get_base_info_page()

        # 登录页面
        self.login_page = CommonPage(self.driver).get_login_info_page()

        # 创建一个数据库对象
        # self.p = AccessDate()

    def tearDown(self):
        # 测试完毕的时候关闭浏览器
        self.driver.quit()

    def login(self, user, passwd):
        self.driver.send_keys('xpath=//*[@id="username"]', user)
        self.driver.send_keys('xpath=//*[@id="password"]', passwd)
        self.driver.click('xpath=//*[@id="app"]/div/div/div/div/div[3]/div[1]/form/div[3]/div/div/span/button')
        sleep(2)

    # 数据驱动验证
    # @parameterized.expand(get_success())
    # def test_login_right(self, name, password):
    #     print(name, password)
    # self.m = Md()
    # self.driver.send_keys('xpath=//*[@id="username"]', name)
    # self.driver.send_keys('xpath=//*[@id="password"]', password)
    # actual_tip = self.p.get_sql_name(name)
    # get_in_paw = self.m.get_md5(password)
    # expect_tip_paw = self.p.get_sql_paw(name)
    # self.assertEqual(get_right_tips, actual_tip[0])
    # self.assertEqual(expect_tip_paw[0][0], get_in_paw)

    # ddt驱动
    # @data(*fileOperate.get_csv_data('account.csv'))
    # @unpack
    # def test_AddResouses(self, username, password):
    #     self.login(username, password)
    #     RandomName = BusinessOperate.getChinsesName()
    #     self.newVolume(RandomName)


if __name__ == '__main__':
    unittest.main()
